﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Model;
using System.Web;
using XProject.DataVisit.Factory;

namespace XProject.DataVisit.Handler.View.BaseManager.PersonManager
{
    public class AreaView:AbstractView
    {
        private UserInfo CurrentUser;
        public override void init()
        {
            if (HttpContext.Current.Session["UserInfo"] != null)
            {
                CurrentUser = HttpContext.Current.Session["UserInfo"] as UserInfo;
                base.init();
            }
            else
            {
                return;
            }
        }
        /// <summary>
        /// 增加地区
        /// </summary>
        public void AddArea()
        {
            var area = JsonRequest.GetParam<Area>("area");
            area.Creater = CurrentUser.PID;
            area.LastUpdate = DateTime.Now;
            JsonResponse.ResponseObject= DaoFactory.AreaDao.Save(area);
        }
        /// <summary>
        /// 修改地区
        /// </summary>
        public void UpdateArea()
        {
            var area = JsonRequest.GetParam<Area>("area");
            area.Creater = CurrentUser.PID;
            area.LastUpdate = DateTime.Now;
            JsonResponse.ResponseObject = DaoFactory.AreaDao.Update(area);
        }

        public void AreaData()
        {
            JsonResponse.ResponseObject = DaoFactory.AreaDao.GetParentList();
        }

        public void DelArea()
        {
            var PID = JsonRequest.GetParam<string>("PID");
            var currentdata = DaoFactory.AreaDao.GetById(new Guid(PID));
            JsonResponse.ResponseObject = DaoFactory.AreaDao.Delete(currentdata);
        }

        #region 设备管理
        public void AddEquipment()
        {
            var cu = JsonRequest.GetParam<Equipment>("equi");
            cu.LastUpdate = DateTime.Now;
            cu.Creater = CurrentUser.PID;
            JsonResponse.ResponseObject = DaoFactory.EquipmentDao.Save(cu);
        }

        public void UpdateEquipment()
        {
            var cu = JsonRequest.GetParam<Equipment>("equi");
            cu.LastUpdate = DateTime.Now;
            cu.Creater = CurrentUser.PID;
            JsonResponse.ResponseObject = DaoFactory.EquipmentDao.Update(cu);
        }

        public void GetEquipmentList()
        {
            var PID = JsonRequest.GetParam<string>("ID");
            JsonResponse.ResponseObject = DaoFactory.EquipmentDao.GetListByOKey(new Guid(PID));
        }

        public void DelEquipment()
        {
            var cu = JsonRequest.GetParam<Equipment>("equi");
            JsonResponse.ResponseObject = DaoFactory.EquipmentDao.Delete(cu);
        }
        #endregion

        #region 广告管理
        public void AddGY()
        {
            var cu = JsonRequest.GetParam<GY>("gy");
            JsonResponse.ResponseObject = DaoFactory.GYDao.Save(cu);
        }

        public void GetGYList()
        {
            var PID = JsonRequest.GetParam<string>("ID");
            JsonResponse.ResponseObject = DaoFactory.GYDao.GetListByOKey(new Guid(PID));
        }
        #endregion

        #region 模版管理
        public void AddModel()
        {
            var cu = JsonRequest.GetParam<XProject.DataVisit.Model.Model>("model");
            JsonResponse.ResponseObject = DaoFactory.ModelDao.Save(cu);
        }

        public void GetModelList()
        {
            JsonResponse.ResponseObject = DaoFactory.ModelDao.GetAll();
        }
        #endregion
    }
}
